//
// Created by lyc on 2024/5/5.
//
#pragma once
#include"product.cpp"
#include"C:\Users\lyc\Desktop\2\2.2\OOP\OOP_experiment\experiment_2\management.cpp"
class ProductManagement{
private:
    string m_name;
public:
    ProductManagement(string pname){
        this->m_name = pname;
    }
    int findProduct();
    void printProduct();
};
//bool ProductManagement::isRoot() {
//    if(LOGIN_STATE==USER){
//        return USER;
//    }
//    if(LOGIN_STATE==ROOT){
//        return ROOT;
//    }
//    else EXIT_FAILURE;
//}

int ProductManagement::findProduct() {
    fstream file(R"(C:\Users\lyc\Desktop\2\2.2\OOP\OOP_experiment\experiment_3\product.txt)");
    if(!file){
        cerr<<"Unable to open file!"<<endl;
        EXIT_FAILURE;
    }
    string line;
    string line_name;
    while(getline(file,line)){
            if(line=="Product"){
                getline(file,line_name);
                if(line_name=="name:  "+m_name){
                    return true;
                }
            }
    }
    return false;
}

void ProductManagement::printProduct() {
    fstream file(R"(C:\Users\lyc\Desktop\2\2.2\OOP\OOP_experiment\experiment_3\product.txt)");
    string line;
    while(getline(file,line)){
        cout<<line<<endl;
    }
}

